require(["config"],function(){
    require(["jquery","cookie","load"],function($){
        function login() {
            this.init();
            $.cookie.json = true;
        };
        $.extend(login.prototype,{
            init() {
                $(".submit").on("click",$.proxy(this.loginUsername,this));
            },
            loginUsername(){
                const reg  = /^1(3|4|5|7|8)\d{9}$/;
                if(reg.test($("#username").val())){
                    const data = $(".loginUser").serialize();
                    $.post("http://127.0.0.1/api/login.php",data,res => {
                        const name = JSON.parse(res);
                        if(name.res_body.status != 0){
                            $.cookie("Username",name.res_body.info.username,{path: "/"});
                            location.href = "/index.html";
                        }else{
                            alert("密码错误")
                        }
                    })
                }else{
                    alert("请输入正确的手机号码")
                }
            }
        });
        new login();
    })
})